/**
 * @param {string[]} tokens
 * @return {number}
 */
export var evalRPN = function (tokens) {
  const stack = []
  for (let i = 0; i < tokens.length; i++) {
    const item = tokens[i]
    if (['+', '-', '*', '/'].includes(item)) {
      const b = stack.pop()
      const a = stack.pop()
      if (item === '+') {
        stack.push(a + b)
      } else if (item === '-') {
        stack.push(a - b)
      } else if (item === '*') {
        stack.push(a * b)
      } else if (item === '/') {
        const div = a / b
        stack.push(div > 0 ? Math.floor(div) : Math.ceil(div))
      }
    } else {
      stack.push(parseInt(item))
    }
  }
  return stack.pop()
}
